package com.aponteitor.business.model;

import java.io.Serializable;

import com.wellsantos.core.util.CommonUtil;
import com.wellsantos.core.util.ReflectUtil;

/**
 * @author penetrol@gmail.com
 */
public abstract class BaseEntity<T extends Serializable> implements Serializable, Cloneable {

	private static final long serialVersionUID = 432562698792664653L;

	public abstract T getId();

	@Override
	public boolean equals(Object obj) {
		if (obj == null || obj.getClass() != getClass()) {
			return false;
		}
		return CommonUtil.equals(getId(), ((BaseEntity<?>)obj).getId());
	}

	@Override
	public int hashCode() {
		Object pk = getId();
		return pk == null ? 0 : pk.hashCode();
	}

	@Override
	public String toString() {
	    return ReflectUtil.toStringFromProperties(this);
	}
	
	public Object clone(){
	    try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
	}
}
